package com.day03;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FileProvider implements IPersonProvider{
    private File file;
    public FileProvider(File file){
    	this.file=file;
    }
	public List<Person> getPersonList(){
		String string=null;
		int i=0;
		BufferedReader bf=null;
		List<Person> list =new ArrayList<Person>();
		try {
		bf=new BufferedReader(new FileReader(file));
			while((string=bf.readLine())!=null){
				i=i+1;
				if(string!=null&&i>1){
				String str[]=string.split(",");
				Person p=new Person();
				p.setFirstName(str[0]);
				p.setLastName(str[1]);
				p.setCompanyName(str[2]);
				p.setAddress(str[3]);
				p.setCity(str[4]);
				p.setCounty(str[5]);
				p.setPostal(str[6]);
				p.setPhone1(str[7]);
				p.setPhone2(str[8]);
				p.setEmail(str[9]);
				p.setWeb(str[10]);
				list.add(p);	
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				bf.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	    return list;
	}
}
